<?
class Tool {
    
    /**
     * 无限级分类
     * @access public 
     * @param Array $data     //数据库里获取的结果集 
     * @param Int $pid             
     * @param Int $count       //第几级分类
     * @return Array $list   
     */
    static public $list = array();
    static public function tree(&$data,$pid = 0,$count = 1) {
        foreach ($data as $key => $value){
            if($value['topid']==$pid){
                $value['Count'] = $count;
                self::$list []=$value;
                unset($data[$key]);
                self::tree($data,$value['id'],$count+1);
            } 
        }
        return self::$list;
    }
    
    
    /**
     * 后台左侧菜单无限级分类
     * @access public 
     * @param Array $data     //数据库里获取的结果集 
     * @param Int $pid             
     * @param Int $count       //第几级分类
     * @return Array $list   
     */
    static public function tree2(&$data,$pid = 0,$count = 1) {
        foreach ($data as $key => $value){
            if($value['topid']==$pid){
                $value['Count'] = $count;
                self::$list []=$value;
                unset($data[$key]);
                self::tree2($data,$value['menuid'],$count+1);
            } 
        }
        return self::$list;
    }
    
}